package com.wanho.java159.base.po;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.util.Date;

public abstract class BaseEntity {
    @Id
    @Field(type = FieldType.Long, store = true)
    private Long  id;

    private Long createBy;

    private Date createTime;

    private Date updateTime;

    private Boolean isDeleted;

    private String remark;

    /**
     * 解决 从数据库查询的long类型 转成 json格式 精度问题
     * 比如：数据库中 id：863525989597188096
     *       JSON中   id: 863525989597188100
     * @return
     */
    @JsonSerialize(using = ToStringSerializer.class)
    public Long getId() {
        return id;
    }

    /**
     * 从前端传值的同样精度问题
     * @param id
     */
    public void setId(@JsonSerialize(using = ToStringSerializer.class) Long id) {
        this.id = id;
    }

    public Long getCreateBy() {
        return createBy;
    }

    public void setCreateBy(Long createBy) {
        this.createBy = createBy;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Boolean getIsDeleted() {
        return isDeleted;
    }

    public void setIsDeleted(Boolean isDeleted) {
        this.isDeleted = isDeleted;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark == null ? null : remark.trim();
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("BaseEntity{");
        sb.append("id=").append(id);
        sb.append(", createBy=").append(createBy);
        sb.append(", createTime=").append(createTime);
        sb.append(", updateTime=").append(updateTime);
        sb.append(", isDeleted=").append(isDeleted);
        sb.append(", remark='").append(remark).append('\'');
        sb.append('}');
        return sb.toString();
    }
}
